package com.explorex.infra.puma.gateway.netty.ws.message.handler;

import com.explorex.infra.puma.gateway.netty.ws.WebSocketSession;
import com.explorex.infra.puma.gateway.netty.ws.enums.MessageTypeEnum;
import com.explorex.infra.puma.gateway.netty.ws.message.Message;
import com.explorex.infra.puma.gateway.netty.ws.message.MessageBody;
import com.explorex.infra.puma.gateway.netty.ws.message.MessageHeader;
import com.explorex.infra.puma.gateway.netty.ws.message.RespMessageBody;
import lombok.Data;

import java.io.Serializable;

/**
 * @author: JacceYang
 * @createTime: 2022/07/15 1:29 下午
 * @description: 空处理器
 */
public class EmptyMessageProcessor implements BaseProcessor {

    public static final BaseProcessor EMPTY_PROCESSOR = new EmptyMessageProcessor();
    public static final Message EMPTY_MESSAGE = new Message();
    public static final EmptyMessage EMPTY_MESSAGE_BODY = new EmptyMessage();

    static {
        EMPTY_MESSAGE.setHeader(new MessageHeader(MessageTypeEnum.ERROR.getType()));
        EMPTY_MESSAGE.setBody(EMPTY_MESSAGE_BODY);
    }

    @Override
    public short getMessageType() {
        return -1;
    }

    @Override
    public Message process(WebSocketSession session, Message messageFrame) {
        return EMPTY_MESSAGE;
    }

    @Override
    public MessageBody parseBody(int contentType, String msgBody) {
        return null;
    }


    @Data
    public static class EmptyMessage extends RespMessageBody implements Serializable {
        private int code = -1;
        private String msg = "failed";
    }
}
